

<template>
  <view class=" w50_1" @tap="toProdPage">
    <view class="image-wrapper_6 flex-row justify-between">
      <image mode="aspectFill" v-if="item.pic" :src="item.pic" class="image_21" />
      <image mode="aspectFill" v-else src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/def.png" class="image_21" />
    </view>
    <view class="hot-text">
      <view class="hotprod-text clamp_text_2">{{ item.prodName }}</view>
      <view v-if="sts==6" class="prod-info clamp_text">{{ item.prodCommNumber }}{{ i18n.evaluation }} {{ item.positiveRating }}%{{ i18n.praise }}</view>
      <view class="prod-text-info" :class="{'collection-row':showCancelCollect || showSoldNum}">
        <view class="price clamp_text">
          <text v-if="sts==2" class="deadline-price">{{ i18n.timeLimitedPrice }}</text>
          <text class="symbol">￥</text>
          <text class="big-num font_weight_6">{{ item.price_1 }}</text>
          <text class="small-num">.{{ item.price_2 }}</text>
          <text v-if="item.totalSoldNum" class="prod-info sold-num">{{ i18n.sold }} {{ item.totalSoldNum }}</text>
        </view>
        <view v-if="item.sts === '5'" class="collection-btn price small-num" @tap.stop="handleCancelCollection">
          {{ i18n.cancelCollect }} </view>
        <!-- <text class="cate-prod-info clamp_text">{{ i18n.sold }} {{ item.totalSoldNum||'99+' }}</text> -->
      </view>
    </view>
  </view>
</template>

<script module="wxs" lang="wxs" src="../../wxs/number.wxs"></script>

<script>
var http = require("../../utils/http.js");

export default {
  data () {
    return {};
  },

  components: {},
  props: {
    item: Object,
    sts: String,
    showCancelCollect: Boolean,
    showSoldNum: {
      type: Boolean,
      default: false
    }
  },

  computed: {
    i18n () {
      return this.$t('index')
    }
  },

  methods: {
    toProdPage () {
      this.$Router.push({ path: '/pages/prod/prod', query: { prodid: this.item.prodId } })
    },
    handleCancelCollection () {
      var params = {
        url: "/p/user/collection/addOrCancel",
        method: "POST",
        data: this.item.prodId,
        callBack: (res) => {
          uni.showToast({
            title: res ? this.i18n.collectionAdded : this.i18n.collectionCancelled,
            duration: 1200,
            icon: 'none',
          })
          this.$emit('getCollectionProd')
        }
      };
      http.request(params);
    }
  }
};
</script>
<style   scoped lang='scss'>
@import "./index.scss";
</style>
